import { defineStore } from "pinia";
import { GlobalState } from "@/stores/interface";
import { typeStatus } from "@/interface/public";

export const useGlobalStore = defineStore({
  id: "global",
  // 修改默认值之后，需清除 localStorage 数据
  state: (): GlobalState => ({
    messageStatus: "success",
    message: "",
    loading: false,
    loadingMessage: "",
    modalLoading: false,
    tabbarValue: "home",
    getVersion: false // 是否获取版本号
  }),
  actions: {
    // Set GlobalState
    setGlobalState(...args: ObjToKeyValArray<GlobalState>) {
      this.$patch({ [args[0]]: args[1] });
    },
    // 清空消息
    clearMessage() {
      this.messageStatus = "";
      this.message = "";
    },
    // 设置消息
    setMessage(message: string = "操作成功", messageStatus: typeStatus["message"] = "success") {
      this.messageStatus = messageStatus;
      this.message = message;
      console.log(this.messageStatus, this.message, "this.message");
    }
  }
});
